def solve(prices):
    n = len(prices)
    min_price = float("inf")
    res = 0
    for i in range(n):
        min_price = min(min_price, prices[i])
        res = max(res, prices[i] - min_price)

    return res


if __name__ == "__main__":
    prices = [7, 1, 5, 3, 6, 4]
    print(solve(prices))
